package com.xxx.util;

import org.solar.generator.Generator;
import org.solar.util.BaseUtil;

import java.net.URLEncoder;

public class GenerateCodeUtil {

    static String packagePrefix;//根据当前class的包路径自动取值
    public static String jdbcUrl = Config.get("DBurl") + "&user=" + Config.get("DBuserName") + "&password=" + URLEncoder.encode(Config.get("DBpassword"));
    public static String pojectPath;
    public static String classPath;
    static String vueHtmlRootPath;
    static String apiHtmlDocPath;
    static{
        String targetClassPath=BaseUtil.getClassPath(GenerateCodeUtil.class);
        pojectPath=targetClassPath.replace("/target/classes/","/");
        classPath = pojectPath + "src/main/java/";
        vueHtmlRootPath = pojectPath + "src/main/webapp/static/";
        apiHtmlDocPath = pojectPath + "src/main/webapp/static/apiHtmlDoc.html";
        packagePrefix = GenerateCodeUtil.class.getCanonicalName().replace(".util.GenerateCodeUtil",".");
    }
    public static void main(String[] args) throws Exception {
        Generator generator = new Generator(jdbcUrl, classPath, packagePrefix);
        generator.mapperXMLGenerator.fullTextSearchContainDate = false;
        generator.vueHtmlRootPath = vueHtmlRootPath;
        //生成包和基本类
        generator.generatePackageAndBaseDaoAndBaseService();
        //生成DaoServiceControllerCode
        generator.generateDaoServiceControllerCode();
        //根据数据库生成实体文件
        generator.overWriteFile = true;
        generator.generateBean();
        generator.generateMybatisMapperXML();

        //生成VUE的CRUD界面
        generator.generateVueWithElementUICode();
        //生成数据库字段与备注的properties
        generator.dataBaseFieldDictPath = pojectPath + "src/main/resources/dataBaseFieldDict.properties";
        generator.generatorDataBaseFieldDict();
        //生成api 文档
        generator.apiHtmlDocPath = apiHtmlDocPath;
        generator.apiHtmlDocHost = "http://api.heduim.com";
        generator.generateApiHtmlDoc();
    }
}
